package IC.Types;

import IC.AST.ICClass;

/**
 * Created by IntelliJ IDEA.
 * User: nimrod
 * Date: 09/01/12
 * Time: 14:35
 * To change this template use File | Settings | File Templates.
 */
public class ClassType extends Type{
    private ICClass icClass;
    private ClassType superType;

    //assumes superclass exists in instances (if there is a superclass).
    public ClassType(ICClass icClass, ClassType superType) {
        super(icClass.getName());
        this.icClass = icClass;
        this.superType = superType;
    }

    public ICClass getIcClass() {
        return icClass;
    }

    @Override
    public boolean subtypeOf(Type t) {
        boolean result = (t == this);

        if (!result && this.superType != null) {
            result = this.superType.subtypeOf(t);
        }

        return result;
    }

    @Override
    public boolean isReferenceType() {
        return true;
    }

    @Override
    public String toString() {
        String result = this.getId() + ": Class: " + this.getName();
        if (this.superType != null) {
            result += ", Superclass ID: " + this.superType.getId();
        }

        return result;
    }
}
